<template>
  <view>
    <view class="hrader">
      <image
        src="../../../static/bback.png"
        class="goback"
        @click="back"
        mode=""
      />
      设置
    </view>
    <view class="" style="padding-top: 86rpx">
      <!-- <navigator url="../Account/Account" class="anquan">
				<view class="" style="padding-left: 30rpx;">账号与安全</view>
				<image src="../../../static/PersonalCenter/right.png" mode="" class="right"></image>
			</navigator> -->
      <!-- <navigator url="../newNews/newNews" class="anquan">
				<view class="" style="padding-left: 30rpx;">新消息通知</view>
				<image src="../../../static/PersonalCenter/right.png" mode="" class="right"></image>
			</navigator> -->
      <!-- <navigator url="../Privacy/Privacy" class="anquan">
				<view class="" style="padding-left: 30rpx;">隐私</view>
				<image src="../../../static/PersonalCenter/right.png" mode="" class="right"></image>
			</navigator> -->
      <!-- <navigator url="../currency/currency" class="anquan">
				<view class="" style="padding-left: 30rpx;">通用</view>
				<image src="../../../static/PersonalCenter/right.png" mode="" class="right"></image>
			</navigator> -->
      <view class="anquan" @click="xiugM">
        <view class="" style="padding-left: 30rpx">修改登录密码</view>
        <image
          src="../../../static/PersonalCenter/right.png"
          mode=""
          class="right"
        ></image>
      </view>
      <view class="anquan" @click="logOut">
        <view class="" style="padding-left: 30rpx">退出登录</view>
        <image
          src="../../../static/PersonalCenter/right.png"
          mode=""
          class="right"
        ></image>
      </view>

      <!-- <view class="anquan">
				<view class="" style="padding-left: 30rpx;">清楚缓存</view>
				<image src="../../../static/PersonalCenter/right.png" mode="" class="right"></image>
			</view> -->
    </view>
    <!-- 退出登录弹窗 -->
    <uni-popup ref="popup" type="center">
      <view class="popCenter">
        <view class="tips">温馨提示</view>
        <text style="padding: 40rpx 0">您确定要退出登录吗？</text>
        <view class="popBtn">
          <text class="cancel" @click="showClcik">取消</text>
          <text
            class="cancel"
            @click="quitClcik"
            style="border: 0; color: #c52b2e"
            >确定</text
          >
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
export default {
  data() {
    return {
      token: "",
      back() {
        uni.switchTab({
          url: "../users",
        });
      },
      userInfo: {},
    };
  },
  onShow() {
    this.token = uni.getStorageSync("token");
    if (this.token) {
      this.getuserInfo();
    }
  },
  methods: {
    // 获取用户信息
    async getuserInfo() {
      let that = this;
      const res = await that.$myRequest({
        url: "user/getUserInfo",
        method: "GET",
        data: {},
      });
      if (res.data.code == 1) {
        that.userInfo = res.data.data;
        uni.setStorageSync("userInfo", res.data.data);
      }
    },
    // 修改密码
    xiugM() {
      if (this.userInfo.mobile) {
        uni.navigateTo({
          url: "../Changepassword/Changepassword",
        });
      } else {
        // 显示加载中 效果
        uni.showLoading({
          title: "请先绑定手机号",
          mask: true,
        });
        setTimeout(function () {
          uni.navigateTo({
            url: "../binding/binding",
          });
        }, 800);
      }
    },
    // 退出登录
    logOut() {
      this.$refs.popup.open();
    },
    async quitClcik() {
      let that = this;
      const res = await that.$myRequest({
        url: "user/logout",
        method: "POST",
        data: {
          token: this.token,
        },
      });
      if (res.data.code == 1) {
        uni.removeStorage({
          key: "token",
          success: function (res) {
            uni.navigateTo({
              url: "../pasLogin/Login",
            });
          },
        });
      }
    },
    showClcik() {
      this.$refs.popup.close();
    },
  },
};
</script>

<style lang="scss">
page {
  width: 100%;
  height: auto;
  background: #f4f4f4;
}
.hrader {
  width: 100%;
  height: 88rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  position: relative;
  font-size: 36rpx;
  font-weight: 500;
  color: #333333;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99;
  .goback {
    position: absolute;
    width: 22rpx;
    height: 34rpx;
    left: 28rpx;
  }
}
.anquan {
  width: 100%;
  height: 102rpx;
  background-color: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20rpx auto;
  font-size: 30rpx;
  font-weight: 400;
  color: #333333;
  .right {
    width: 12rpx;
    height: 24rpx;
    padding-right: 30rpx;
  }
}
.popCenter {
  display: flex;
  align-items: center;
  flex-direction: column;
  width: 546rpx;
  padding: 40rpx 0 0;
  background-color: #fff;
  font-size: 30rpx;
  color: #333333;
  border-radius: 10rpx;
  .tips {
    text-align: center;
    font-size: 30rpx;
    font-weight: 550;
    color: #373737;
  }
  .popBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100rpx;
    border-top: 1rpx solid #eee;
    border-radius: 0 0 10rpx 10rpx;

    .cancel {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 28rpx;
      color: #373737;
      width: 50%;
      height: 100%;
      border-right: 1rpx solid #eee;
      letter-spacing: 2rpx;
    }
  }
}
</style>
